﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            f1.ShowDialog();
            textBox2.Text = f1.SelectedPath.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            f2.ShowDialog();
            textBox3.Text = f2.SelectedPath.ToString();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //if (f1.SelectedPath.ToString() == "" || f2.SelectedPath.ToString() == "")
            //{
                //textBox1.Text = "Wybierz 2 foldery.";
            //}
            //else
            //{
                FileInfo[] files1 = getFilesFromFolder(f1.SelectedPath.ToString());
                FileInfo[] files2 = getFilesFromFolder(f2.SelectedPath.ToString());

                foreach (FileInfo a in files1)
                {
                    foreach (FileInfo b in files2)
                    {
                        StreamReader sr = File.OpenText(f1.SelectedPath.ToString() + "/" + a.ToString());
                        string plik_a = sr.ReadToEnd();
                        sr.Close();
                        StreamReader sr2 = File.OpenText(f2.SelectedPath.ToString() + "/" + b.ToString());
                        string plik_b = sr2.ReadToEnd();
                        sr.Close();
                        if (plik_a == plik_b)
                        {
                        string[] cell = new string[2]; 
                        int s = 2;
                        for (int i = 0; i < s; i++)
                        { 
                                cell[0] = f1.SelectedPath.ToString() + "\\" + a.ToString();
                                cell[1] =  f2.SelectedPath.ToString() + "\\" + b.ToString();
                                
                                dataGridView1.Rows.Add(cell);

                        }
                        dataGridView1.Invalidate();

                           
                        }
                    }
                }
            }
       // }
        private static FileInfo[] getFilesFromFolder(string path)
        {
            DirectoryInfo folder1 = new DirectoryInfo(path);
            return folder1.GetFiles();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
